|
|
|
|
|
|
|
The final item on the Format menu is the Size to Griditem. Selecting this option sets the Height and Width properties of each selected control so that it exactly matches the grid spacing. |
|
|
|
|
|
|
|
|
Multiple Controls in a Frame |
|
|
|
|
|
|
|
|
Now you know how to select multiple controls on a form to work with their common properties or to handle alignment and sizing tasks. You can use the same approach with controls inside a frame. The only difference is in the way that you select the controls. To select a group of controls, you first need to click the form so that no controls are selected. Then hold down the Shift or Ctrl key while you click, and drag the mouse around the controls in the frame. This action selects the group of controls. You can still select or deselect other controls by holding down the Ctrl key while you click the controls. |
|
|
|
|
|
|
|
|
|
When you are selecting a group of controls, all the controls must be inside or outside a container. Also, control selection cannot span containers.  |
|
|
|
|
|
|
|
|
|
|
After you select the multiple controls, you can work with their common properties or use the commands of the Format menu to position and size the controls. |
|
|
|
|
CAUTION
|
|
|
|
|
The Center in Form command of the Format menu still centers the controls in the form, not within the frame. This result may be undesirable. |
|
|
|
|
|
|
|
|
|
|
Working with the Controls Collection |
|
|
|
|
|
|
|
|
By now, you're probably thinking, "All this is great when I am in the design environment, but what about while my program is running?" Well, as you know, you can change the properties of any single control by specifying the control name, the property name, and the new property value. But does this mean that you have to set each control individually? No way! |
|
|
|
|
|
|
|
|
Each form contains a collection called the Controls collection. This collection identifies each control on the form. Using this collection and a special form of the For loop, you can change a specific property of every control on your form. |
|
|
|
|
|
|
|
|
As an example of changing controls, you might want to give your users a way to select the font they want to use for the controls on the form. Trying to set each form in code would be a real pain. But, with the For Each loop, you can set the font of every control on the form with just three lines of code: |
|
|
|
|
|
|
|
|
For Each Control In Form1.Controls
Control.Font = "Times New Roman"
Next Control |
|
|
|
|
|